//
//  BaseTabBarItem.swift
//  GreenDeal
//
//  Created by Moennig Q on 2023/4/21.
//

import UIKit
import RxSwift
class BaseTabBarItem: UITabBarItem {
    private lazy var disposeBag = DisposeBag()
    let standardFontSize: CGFloat = 9
    override init() {
        super.init()
        if UIDevice.getBottomAreaHeight() == 0{
            self.titlePositionAdjustment = UIOffset(horizontal: 0, vertical: -15)//调整title的位置，预留10的位置给网络是否连接的浮动视图使用
        }
        self.setTitleTextAttributes([NSAttributedString.Key.font : R.font.interRegular(size: self.standardFontSize)!], for: UIControl.State.normal)
        //监听字体变化
        Constant.standardViewFlagSuject.subscribe { [weak self] _ in
            guard let strongSelf = self else {return}
            var realFontSize = strongSelf.standardFontSize
            if !Constant.standardViewFlag {
                realFontSize = strongSelf.standardFontSize * Constant.magnifiedViewScale
            }
            strongSelf.setTitleTextAttributes([NSAttributedString.Key.font : R.font.interRegular(size: realFontSize)!], for: UIControl.State.normal)
        }.disposed(by: self.disposeBag)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
